package com.itqf.controller;

import com.itqf.aop.MyLog;
import com.itqf.entity.SysMenu;
import com.itqf.service.SysMenuService;
import com.itqf.utils.R;
import com.itqf.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/10/20
 * @Time: 上午9:54
 */
@RestController
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;

    @RequestMapping("/sys/menu/user")
    @MyLog(value = "查询用户的菜单和权限",description = "查询用户的菜单和权限")
    public R menuListAndPerms(){

       return  sysMenuService.findUserMenuAndPerms(ShiroUtils.getUId());

    }

    @RequestMapping("/sys/menu/list")
    @MyLog(value = "查询所有菜单",description = "分页查询菜单和权限")
    //http://localhost:8080/sys/menu/list?order=asc&limit=10&offset=0
    public   R  menuList(int limit,int offset,String order,String search){

        return  sysMenuService.findMenuByPage(limit,offset,order,search);
    }


    /**
     * 查询目录和菜单
     * 树形结构展示
     */
    @RequestMapping("/sys/menu/select")
    @MyLog(value = "查询所有目录和菜单",description = "查询所有目录和菜单，并且以树形结构展示")
    public    R   menuTree(){

        return  sysMenuService.findMenuTree();
    }

    @RequestMapping("/sys/menu/save")
    @MyLog(value = "新增菜单、目录或者按钮",description = "新增菜单、目录或者按钮")

    public   R  addMenu(@RequestBody SysMenu sysMenu){

        return  sysMenuService.save(sysMenu);
    }

    @RequestMapping("/sys/menu/del")
    @MyLog(value = "删除菜单",description = "使用假删除实现删除菜单")
    public   R  del(@RequestBody List<Long> ids){

        return  sysMenuService.del(ids);
    }

}
